package com.ibm.spatiotemp.datamodel.datatype.request;

import com.ibm.spatiotemp.source.GPSDataSouceFactory;
import com.ibm.spatiotemp.source.GPSDataSource;

public class BuildIdxRequest extends Request {
	
	public final static String STARTTS = "starttss";
	public final static String ENDTS = "endts";
	public final static String TIMESCALE = "time_scale";
	public final static String FIRSTIDXLAYERPATH = "firstlayeridxpath";
	public final static String SECONDIDXLAYERPATH = "secondlayeridxpath";

	public long startts;
	public long endts;
	public long time_scale;/*unit msec*/
	
	public long getStartts() {
		return startts;
	}
	public void setStartts(long startts) {
		this.startts = startts;
	}
	public long getEndts() {
		return endts;
	}
	public void setEndts(long endts) {
		this.endts = endts;
	}
	
	public String firstlayeridxpath;
	public String secondlayeridxpath;

	public static final String FirstLayerIdxPathSchema = "%s/rtree_1st/%d/";
	public static final String SecondLayerIdxPathSchema = "%s/rtree_2nd/";
	
	public String getFirstlayeridxpath() {
//		firstlayeridxpath = datasrcid+"/"+"rtree_1st"+"/" + startts+"_" + endts;
		String dsrcname = this.getDatasrcid();
		GPSDataSource dsrc  = GPSDataSouceFactory.getGPSDataSource(dsrcname);
		long scale = dsrc.getIndexScale();
		long starts = this.getStartts() < dsrc.getMostEarlyTimeStamp() ? dsrc.getMostEarlyTimeStamp():this.getStartts();
//		long endts = this.getEndts();
		
		int scaled_startts = (int)((starts)/scale);
//		int scaled_endts = (int)((endts)/scale);
		firstlayeridxpath = String.format(FirstLayerIdxPathSchema, dsrcname,scaled_startts);
		return firstlayeridxpath;
	}
	public long getTime_scale() {
		return time_scale;
	}
	public void setTime_scale(long time_scale) {
		this.time_scale = time_scale;
	}
	public String getSecondlayeridxpath() {
//		secondlayeridxpath = 
//				datasrcid+"/"+"rtree_2nd"+"/";
//		String dsrcname = this.getDatasrcid();
		secondlayeridxpath = String.format(SecondLayerIdxPathSchema,datasrcid);
		return secondlayeridxpath;
	}
	
	@Override
	public BuildIdxRequest clone() {
		BuildIdxRequest res = new BuildIdxRequest();
		res.startts = this.startts;
		res.endts = this.endts;
		res.time_scale = this.time_scale;/*unit msec*/
		res.datasrcid = this.datasrcid;
		res.requesttype = this.requesttype;
		return res;
	}

}
